window.onload = function () {
  var vm = new Vue({
    el: "#indexbox",
    data: {
      show: true,
      count: "",
      timer: null,
      username: "", //手机号
      verifyCode: "", //验证码
      name: "", //姓名
      passwordO: "", //密码
      password: "", //密码
      reg: /^1[34578]\d{9}$/,
      corname:1,
      corpsd:1,
      corpsdd:1,
      corpsdpsd:1,
      cortel:1,
      coryzm:1,
      corpsdlen:1,

    },
    created: function () {

    },
    methods: {
      getCode() {
        if (!this.reg.test(this.username)) {
          this.cortel=0;
          return;
        };
        var TIME_COUNT = 120;
        if (!this.timer) {
          this.count = TIME_COUNT;
          this.show = false;
          this.timer = setInterval(() => {
            if (this.count > 0 && this.count <= TIME_COUNT) {
              this.count--;
            } else {
              this.show = true;
              clearInterval(this.timer);
              this.timer = null;
            }
          }, 1000);
          login_server.getVerifyCode({
            type: "0",
            phone: this.username
          }, function (res) {
            console.log(res, "====验证码信息====");
          })
        }
      },
      registered() {
        if (!this.name) {
          if(this.passwordO){
            this.corpsd=1;
          }
          if(this.passwordO.length < 6 || this.passwordO.length < 12){
            this.corpsdlen=1;
          }
          if(this.password){
            this.corpsdd=1;
          }
          if(this.password == this.passwordO){
            this.corpsdpsd=1;
          }
          if(this.reg.test(this.username)){
            this.cortel=1;
          }
          if(this.verifyCode){
            this.coryzm=1;
          }
          this.corname=0;
          return;
        }
        if (!this.passwordO) {
          if(this.passwordO.length < 6 || this.passwordO.length < 12){
            this.corpsdlen=1;
          }
          if(this.password){
            this.corpsdd=1;
          }
          if(this.password == this.passwordO){
            this.corpsdpsd=1;
          }
          if(this.reg.test(this.username)){
            this.cortel=1;
          }
          if(this.verifyCode){
            this.coryzm=1;
          }
          this.corname=1;
          this.corpsd=0;
          return;
        } else if (this.passwordO.length < 6 || this.passwordO.length > 12) {
          if(this.password){
            this.corpsdd=1;
          }
          if(this.password == this.passwordO){
            this.corpsdpsd=1;
          }
          if(this.reg.test(this.username)){
            this.cortel=1;
          }
          if(this.verifyCode){
            this.coryzm=1;
          }
          this.corname=1;
          this.corpsd=1;
          this.corpsdlen=0
          return;
        }
        if (!this.password) {
          if(this.password == this.passwordO){
            this.corpsdpsd=1;
          }
          if(this.reg.test(this.username)){
            this.cortel=1;
          }
          if(this.verifyCode){
            this.coryzm=1;
          }
          this.corname=1;
          this.corpsd=1;
          this.corpsdlen=1;
          this.corpsdd=0;
          return;
        } else if (this.password != this.passwordO) {
          if(this.reg.test(this.username)){
            this.cortel=1;
          }
          if(this.verifyCode){
            this.coryzm=1;
          }
          this.corname=1;
          this.corpsd=1;
          this.corpsdlen=1;
          this.corpsdd=1;
          this.corpsdpsd=0;
          return;
        }
        if (!this.reg.test(this.username)) {
          if(this.verifyCode){
            this.coryzm=1;
          }
          this.corname=1;
          this.corpsd=1;
          this.corpsdlen=1;
          this.corpsdd=1;
          this.corpsdpsd=1;
          this.cortel=0;
          return;
        }
        if (!this.verifyCode) {
          this.corname=1;
          this.corpsd=1;
          this.corpsdlen=1;
          this.corpsdd=1;
          this.corpsdpsd=1;
          this.cortel=1;
          this.coryzm=0;
          return;
        }
        let obj = {
          username: this.username,
          verifyCode: this.verifyCode,
          name: this.name,
          password: this.password
        },$this = this;
        login_server.register(obj, function (res) {
          console.log(res, "=====注册信息====");
          if (res.code == 200) {
            $this.reset()
            window.location.href='../login/loginsuccess.html'
          }else if(res.code==400){
            $this.coryzm=0;
          }
        })
      },
      reset(){
        this.corname=1;
        this.corpsd=1;
        this.corpsdd=1;
        this.corpsdpsd=1;
        this.cortel=1;
        this.coryzm=1;
        this.corpsdlen=1;
      }
    }
  });
};